package com.aiyige.base.db.table;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.aiyige.city.model.City;
import com.aiyige.model.moment.backup.CardBackup;
import com.aiyige.model.moment.backup.TagBackup;
import com.aiyige.model.moment.entity.MajorCourse;
import com.aiyige.model.moment.entity.Moment;
import com.aiyige.page.interest.model.Interest;
import com.aiyige.page.interest.util.InterestUtil;
import com.aiyige.page.publish.majorcourse.model.ClassLocation;
import com.aiyige.page.publish.majorcourse.model.MajorCourseFormModel;
import com.aiyige.page.publish.selectinterest.model.PublishIndustryItem;
import com.aiyige.page.publish.selectinterest.model.PublishInterestItem;
import com.aiyige.page.publish.selecttraingcard.model.TraingCard;
import com.aiyige.page.publish.util.PublishUtil;
import com.aiyige.setup.util.SetupUtil;
import com.aiyige.utils.AccountUtil;
import com.aiyige.utils.DummyDataUtil;
import com.aiyige.utils.ListUtil;
import com.aiyige.utils.MomentUtil;
import com.aiyige.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zhuyakun on 2017/12/14.
 */
@DatabaseTable(tableName = "MajorCourseDBModel")
public class MajorCourseDBModel implements Parcelable, MultiItemEntity {
    public static final String ID = "id";
    public static final String CONTROL_OPTION = "controlOption";
    public static final String PROGRESS_STATUS = "progressStatus";
    public static final String USER_ID = "userId";
    public static final String GOODS_ID = "goodsId";
    public static final String ROUTER = "router";
    public static final String RETRY_COUNT = "retryCount";
    public static final String TRAING_CARD = "traingCard";
    public static final String JOIN_CONSUMPTION_SECURITY_PLAN = "joinConsumptionSecurityPlan";
    @DatabaseField(id = true, columnName = ID)
    String id;

    @DatabaseField(columnName = USER_ID)
    String userId;

    @DatabaseField
    String title;

    @DatabaseField
    String interest;

    @DatabaseField
    String industry;

    @DatabaseField
    boolean openBuy;

    @DatabaseField(columnName = JOIN_CONSUMPTION_SECURITY_PLAN)
    boolean joinConsumptionSecurityPlan;

    @DatabaseField
    String classSize;

    @DatabaseField
    int openClassCondition;

    @DatabaseField
    String minClassSize;

    @DatabaseField
    Long confirmDate;

    @DatabaseField
    Long startClassDate;

    @DatabaseField
    Long endClassDate;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String classLocation;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String suitableLearnAge;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String learnTarget;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String suitablePeople;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String majorCourseType;

    @DatabaseField
    String price;

    @DatabaseField
    String platformDividend;

    @DatabaseField
    String courseNumber;

    @DatabaseField(columnName = TRAING_CARD, dataType = DataType.LONG_STRING)
    String traingCard;

    @DatabaseField
    String singlePrice;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String courseDesc;

    @DatabaseField
    String coverUrl;

    @DatabaseField
    String coverStoreKey;

    @DatabaseField
    boolean coverNeedUpload;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String courseSchedule;

    @DatabaseField
    int publishOperationType;


    @DatabaseField
    String singleClassDuration;

    @DatabaseField(columnName = PROGRESS_STATUS)
    int progressStatus;

    @DatabaseField(columnName = CONTROL_OPTION)
    int controlOption;

    @DatabaseField(columnName = GOODS_ID)
    String goodsId;

    @DatabaseField
    long releaseDate;

    @DatabaseField
    long sellDate;

    @DatabaseField(dataType = DataType.LONG_STRING)
    String guarantee;

    @DatabaseField(columnName = ROUTER)
    String router;

    @DatabaseField(columnName = RETRY_COUNT)
    int retryCount;

    float uploadedPercent = 0f;

    String rejectReason;

    long viewCount;
    long likeCount;
    long commentCount;
    long collectCount;
    long sold;
    double salesVolume;

    int publishSource = PublishUtil.PUBLISH_SOURCE_ANDROID;

    public MajorCourseDBModel() {
    }

    private MajorCourseDBModel(Builder builder) {
        setId(builder.id);
        setUserId(builder.userId);
        setTitle(builder.title);
        setInterest(builder.interest);
        setIndustry(builder.industry);
        setOpenBuy(builder.openBuy);
        setJoinConsumptionSecurityPlan(builder.joinConsumptionSecurityPlan);
        setClassSize(builder.classSize);
        setOpenClassCondition(builder.openClassCondition);
        setMinClassSize(builder.minClassSize);
        setConfirmDate(builder.confirmDate);
        setStartClassDate(builder.startClassDate);
        setEndClassDate(builder.endClassDate);
        setClassLocation(builder.classLocation);
        setSuitableLearnAge(builder.suitableLearnAge);
        setLearnTarget(builder.learnTarget);
        setSuitablePeople(builder.suitablePeople);
        setMajorCourseType(builder.majorCourseType);
        setPrice(builder.price);
        setPlatformDividend(builder.platformDividend);
        setCourseNumber(builder.courseNumber);
        setTraingCard(builder.traingCard);
        setSinglePrice(builder.singlePrice);
        setCourseDesc(builder.courseDesc);
        setCoverUrl(builder.coverUrl);
        setCoverStoreKey(builder.coverStoreKey);
        setCoverNeedUpload(builder.coverNeedUpload);
        setCourseSchedule(builder.courseSchedule);
        setPublishOperationType(builder.publishOperationType);
        setSingleClassDuration(builder.singleClassDuration);
        setProgressStatus(builder.progressStatus);
        setControlOption(builder.controlOption);
        setGoodsId(builder.goodsId);
        setReleaseDate(builder.releaseDate);
        setSellDate(builder.sellDate);
        setGuarantee(builder.guarantee);
        setRouter(builder.router);
        setRetryCount(builder.retryCount);
        setUploadedPercent(builder.uploadedPercent);
        setRejectReason(builder.rejectReason);
        setViewCount(builder.viewCount);
        setLikeCount(builder.likeCount);
        setCommentCount(builder.commentCount);
        setCollectCount(builder.collectCount);
        setSold(builder.sold);
        setSalesVolume(builder.salesVolume);
        setPublishSource(builder.publishSource);
    }


    public static MajorCourseDBModel parse(Moment moment) {
        MajorCourse majorCourse;
        try {
            majorCourse = JSON.parseObject(moment.getMoreBackup(), MajorCourse.class);
        } catch (Exception e) {
            majorCourse = new MajorCourse();
        }
        int progressStatus = PublishUtil.convertMomentStatusToProgressStatus(moment.getStatus());

        List<Interest> interestList = new LinkedList<>();
        List<Interest> industryList = new LinkedList<>();
        for (TagBackup tagBackup : moment.getTags()) {
            if (tagBackup == null || TextUtils.isEmpty(tagBackup.getId())) continue;
            switch (tagBackup.getGroupType()) {
                case SetupUtil.GROUP_TYPE_AVOCATION:
                    interestList.add(InterestUtil.convertTagBackupToInterest(tagBackup));
                    break;
                case SetupUtil.GROUP_TYPE_CHANNEL:
                    industryList.add(InterestUtil.convertTagBackupToInterest(tagBackup));
                    break;
            }
        }
        int openClassCondition = MajorCourseFormModel.OPEN_CLASS_CONDITION_DEPEND_ON_OPEN_DATE;
        try {
            switch (majorCourse.getTakeEffectCondition()) {
                case Moment.COURSE_TAKE_EFFECT_CONDITION_OPEN_DATE:
                    openClassCondition = MajorCourseFormModel.OPEN_CLASS_CONDITION_DEPEND_ON_OPEN_DATE;
                    break;
                case Moment.COURSE_TAKE_EFFECT_CONDITION_POPULATION:
                    openClassCondition = MajorCourseFormModel.OPEN_CLASS_CONDITION_DEPEND_ON_POPULATION;
                    break;
            }
        } catch (Exception e) {

        }
        String classLocationJson;
        try {
            City city = DummyDataUtil.getCityById(moment.getCityId());
            classLocationJson = JSON.toJSONString(ClassLocation.newBuilder()
                    .id(city.getId())
                    .city(city.getCity())
                    .province(city.getProvince())
                    .build());
        } catch (Exception e) {
            classLocationJson = JSON.toJSONString(ClassLocation.newBuilder().build());
        }

        List<TraingCard> traingCardList = new LinkedList<>();
        try {
            for (CardBackup cardBackup : majorCourse.getBindCardBackup()) {
                int traingCardType;
                switch (cardBackup.getCardType()) {
                    case Moment.TRAINING_CARD_TYPE_MEASURED_CARD:
                        traingCardType = TraingCard.TYPE_COUNT_CARD;
                        break;
                    case Moment.TRAINING_CARD_TYPE_RECHARGEABLE_CARD:
                        traingCardType = TraingCard.TYPE_PREPAID_CARD;
                        break;
                    case Moment.TRAINING_CARD_TYPE_TIME_CARD:
                        traingCardType = TraingCard.TYPE_TIME_CARD;
                        break;
                    default:
                        traingCardType = TraingCard.TYPE_TIME_CARD;
                        break;
                }
                traingCardList.add(TraingCard.newBuilder()
                        .id(cardBackup.getId())
                        .type(traingCardType)
                        .title(cardBackup.getTitle())
                        .build());
            }
        } catch (Exception e) {

        }


        return MajorCourseDBModel.newBuilder()
                .userId(AccountUtil.getCurrentUser().getId())
                .title(moment.getTitle())
                .interest(JSON.toJSONString(interestList))
                .industry(JSON.toJSONString(industryList))
                .openBuy(moment.getLetBuy())
                .publishSource(MomentUtil.convertAiyigeApplicationToPublishSource(moment.getAiyigeApplication()))
                .classSize(majorCourse.getStudentMax() == null ? null : String.valueOf(majorCourse.getStudentMax()))
                .openClassCondition(openClassCondition)
                .minClassSize(majorCourse.getStudentMin() == null ? null : String.valueOf(majorCourse.getStudentMin()))
                .confirmDate(majorCourse.getConfirmStartClassDate())
                .startClassDate(majorCourse.getStartDate())
                .endClassDate(majorCourse.getEndDate())
                .classLocation(classLocationJson)
                .price(majorCourse.getPrice() == null ? null : StringUtils.priceFormat(majorCourse.getPrice()))
                .platformDividend(majorCourse.getDivisionProportion() == null ? "" : StringUtils.priceFormat(majorCourse.getDivisionProportion() * 100))
                .courseNumber(majorCourse.getClassCount() == null ? null : String.valueOf(majorCourse.getClassCount()))
                .traingCard(JSON.toJSONString(traingCardList))
                .singlePrice(majorCourse.getUnitPrice() == null ? null : StringUtils.priceFormat(majorCourse.getUnitPrice()))
                .coverUrl(ListUtil.isEmpty(moment.getCover()) ? "" : moment.getCover().get(0))
                .coverNeedUpload(false)
                .singleClassDuration(majorCourse.getDruationPerClass() == null ? null : String.valueOf(majorCourse.getDruationPerClass()))
                .progressStatus(progressStatus)
                .goodsId(moment.getId())
                .releaseDate(moment.getUpdateTime())
                .sellDate(moment.getOnsellTime())
                .router(moment.getRouter())
                .rejectReason(moment.getRemark())
                .sold(moment.getStatisticsBackup().getSellCount())
                .salesVolume(moment.getStatisticsBackup().getSellAmount())
                .likeCount(moment.getStatisticsBackup().getPraiseCount())
                .collectCount(moment.getStatisticsBackup().getFavoriteCount())
                .commentCount(moment.getStatisticsBackup().getCommentCount())
                .viewCount(moment.getStatisticsBackup().getViewCount())
                .joinConsumptionSecurityPlan(majorCourse.getConsumptionGuarantee() == null ? false : majorCourse.getConsumptionGuarantee())
                .build();
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public int getItemType() {
        return PublishUtil.PARENT_TYPE_MAJOR_COURESE;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getInterest() {
        return interest;
    }

    public void setInterest(String interest) {
        this.interest = interest;
    }

    public String getIndustry() {
        return industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public boolean isOpenBuy() {
        return openBuy;
    }

    public void setOpenBuy(boolean openBuy) {
        this.openBuy = openBuy;
    }

    public boolean isJoinConsumptionSecurityPlan() {
        return joinConsumptionSecurityPlan;
    }

    public void setJoinConsumptionSecurityPlan(boolean joinConsumptionSecurityPlan) {
        this.joinConsumptionSecurityPlan = joinConsumptionSecurityPlan;
    }

    public String getClassSize() {
        return classSize;
    }

    public void setClassSize(String classSize) {
        this.classSize = classSize;
    }

    public int getOpenClassCondition() {
        return openClassCondition;
    }

    public void setOpenClassCondition(int openClassCondition) {
        this.openClassCondition = openClassCondition;
    }

    public String getMinClassSize() {
        return minClassSize;
    }

    public void setMinClassSize(String minClassSize) {
        this.minClassSize = minClassSize;
    }

    public Long getConfirmDate() {
        return confirmDate;
    }

    public void setConfirmDate(Long confirmDate) {
        this.confirmDate = confirmDate;
    }

    public Long getStartClassDate() {
        return startClassDate;
    }

    public void setStartClassDate(Long startClassDate) {
        this.startClassDate = startClassDate;
    }

    public Long getEndClassDate() {
        return endClassDate;
    }

    public void setEndClassDate(Long endClassDate) {
        this.endClassDate = endClassDate;
    }

    public String getClassLocation() {
        return classLocation;
    }

    public void setClassLocation(String classLocation) {
        this.classLocation = classLocation;
    }

    public String getSuitableLearnAge() {
        return suitableLearnAge;
    }

    public void setSuitableLearnAge(String suitableLearnAge) {
        this.suitableLearnAge = suitableLearnAge;
    }

    public String getLearnTarget() {
        return learnTarget;
    }

    public void setLearnTarget(String learnTarget) {
        this.learnTarget = learnTarget;
    }

    public String getSuitablePeople() {
        return suitablePeople;
    }

    public void setSuitablePeople(String suitablePeople) {
        this.suitablePeople = suitablePeople;
    }

    public String getMajorCourseType() {
        return majorCourseType;
    }

    public void setMajorCourseType(String majorCourseType) {
        this.majorCourseType = majorCourseType;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getPlatformDividend() {
        return platformDividend;
    }

    public void setPlatformDividend(String platformDividend) {
        this.platformDividend = platformDividend;
    }

    public String getCourseNumber() {
        return courseNumber;
    }

    public void setCourseNumber(String courseNumber) {
        this.courseNumber = courseNumber;
    }

    public String getTraingCard() {
        return traingCard;
    }

    public void setTraingCard(String traingCard) {
        this.traingCard = traingCard;
    }

    public String getSinglePrice() {
        return singlePrice;
    }

    public void setSinglePrice(String singlePrice) {
        this.singlePrice = singlePrice;
    }

    public String getCourseDesc() {
        return courseDesc;
    }

    public void setCourseDesc(String courseDesc) {
        this.courseDesc = courseDesc;
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        this.coverUrl = coverUrl;
    }

    public String getCoverStoreKey() {
        return coverStoreKey;
    }

    public void setCoverStoreKey(String coverStoreKey) {
        this.coverStoreKey = coverStoreKey;
    }

    public boolean isCoverNeedUpload() {
        return coverNeedUpload;
    }

    public void setCoverNeedUpload(boolean coverNeedUpload) {
        this.coverNeedUpload = coverNeedUpload;
    }

    public String getCourseSchedule() {
        return courseSchedule;
    }

    public void setCourseSchedule(String courseSchedule) {
        this.courseSchedule = courseSchedule;
    }

    public int getPublishOperationType() {
        return publishOperationType;
    }

    public void setPublishOperationType(int publishOperationType) {
        this.publishOperationType = publishOperationType;
    }

    public String getSingleClassDuration() {
        return singleClassDuration;
    }

    public void setSingleClassDuration(String singleClassDuration) {
        this.singleClassDuration = singleClassDuration;
    }

    public int getProgressStatus() {
        return progressStatus;
    }

    public void setProgressStatus(int progressStatus) {
        this.progressStatus = progressStatus;
    }

    public int getControlOption() {
        return controlOption;
    }

    public void setControlOption(int controlOption) {
        this.controlOption = controlOption;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public long getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(long releaseDate) {
        this.releaseDate = releaseDate;
    }

    public long getSellDate() {
        return sellDate;
    }

    public void setSellDate(long sellDate) {
        this.sellDate = sellDate;
    }

    public String getGuarantee() {
        return guarantee;
    }

    public void setGuarantee(String guarantee) {
        this.guarantee = guarantee;
    }

    public String getRouter() {
        return router;
    }

    public void setRouter(String router) {
        this.router = router;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }

    public float getUploadedPercent() {
        return uploadedPercent;
    }

    public void setUploadedPercent(float uploadedPercent) {
        this.uploadedPercent = uploadedPercent;
    }

    public String getRejectReason() {
        return rejectReason;
    }

    public void setRejectReason(String rejectReason) {
        this.rejectReason = rejectReason;
    }

    public long getViewCount() {
        return viewCount;
    }

    public void setViewCount(long viewCount) {
        this.viewCount = viewCount;
    }

    public long getLikeCount() {
        return likeCount;
    }

    public void setLikeCount(long likeCount) {
        this.likeCount = likeCount;
    }

    public long getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(long commentCount) {
        this.commentCount = commentCount;
    }

    public long getCollectCount() {
        return collectCount;
    }

    public void setCollectCount(long collectCount) {
        this.collectCount = collectCount;
    }

    public long getSold() {
        return sold;
    }

    public void setSold(long sold) {
        this.sold = sold;
    }

    public double getSalesVolume() {
        return salesVolume;
    }

    public void setSalesVolume(double salesVolume) {
        this.salesVolume = salesVolume;
    }

    public int getPublishSource() {
        return publishSource;
    }

    public void setPublishSource(int publishSource) {
        this.publishSource = publishSource;
    }

    public static final class Builder {
        private String id;
        private String userId;
        private String title;
        private String interest;
        private String industry;
        private boolean openBuy;
        private boolean joinConsumptionSecurityPlan;
        private String classSize;
        private int openClassCondition;
        private String minClassSize;
        private Long confirmDate;
        private Long startClassDate;
        private Long endClassDate;
        private String classLocation;
        private String suitableLearnAge;
        private String learnTarget;
        private String suitablePeople;
        private String majorCourseType;
        private String price;
        private String platformDividend;
        private String courseNumber;
        private String traingCard;
        private String singlePrice;
        private String courseDesc;
        private String coverUrl;
        private String coverStoreKey;
        private boolean coverNeedUpload;
        private String courseSchedule;
        private int publishOperationType;
        private String singleClassDuration;
        private int progressStatus;
        private int controlOption;
        private String goodsId;
        private long releaseDate;
        private long sellDate;
        private String guarantee;
        private String router;
        private int retryCount;
        private float uploadedPercent;
        private String rejectReason;
        private long viewCount;
        private long likeCount;
        private long commentCount;
        private long collectCount;
        private long sold;
        private double salesVolume;
        private int publishSource;

        private Builder() {
            id = "";
            goodsId = "";
            viewCount = 0;
            likeCount = 0;
            commentCount = 0;
            collectCount = 0;
            sold = 0;
            salesVolume = 0;
            publishSource = PublishUtil.PUBLISH_SOURCE_ANDROID;
            joinConsumptionSecurityPlan = false;
            sellDate = 0;
        }

        public Builder id(String val) {
            id = val;
            return this;
        }

        public Builder userId(String val) {
            userId = val;
            return this;
        }

        public Builder title(String val) {
            title = val;
            return this;
        }

        public Builder interest(String val) {
            interest = val;
            return this;
        }

        public Builder industry(String val) {
            industry = val;
            return this;
        }

        public Builder openBuy(boolean val) {
            openBuy = val;
            return this;
        }

        public Builder joinConsumptionSecurityPlan(boolean val) {
            joinConsumptionSecurityPlan = val;
            return this;
        }

        public Builder classSize(String val) {
            classSize = val;
            return this;
        }

        public Builder openClassCondition(int val) {
            openClassCondition = val;
            return this;
        }

        public Builder minClassSize(String val) {
            minClassSize = val;
            return this;
        }

        public Builder confirmDate(Long val) {
            confirmDate = val;
            return this;
        }

        public Builder startClassDate(Long val) {
            startClassDate = val;
            return this;
        }

        public Builder endClassDate(Long val) {
            endClassDate = val;
            return this;
        }

        public Builder classLocation(String val) {
            classLocation = val;
            return this;
        }

        public Builder suitableLearnAge(String val) {
            suitableLearnAge = val;
            return this;
        }

        public Builder learnTarget(String val) {
            learnTarget = val;
            return this;
        }

        public Builder suitablePeople(String val) {
            suitablePeople = val;
            return this;
        }

        public Builder majorCourseType(String val) {
            majorCourseType = val;
            return this;
        }

        public Builder price(String val) {
            price = val;
            return this;
        }

        public Builder platformDividend(String val) {
            platformDividend = val;
            return this;
        }

        public Builder courseNumber(String val) {
            courseNumber = val;
            return this;
        }

        public Builder traingCard(String val) {
            traingCard = val;
            return this;
        }

        public Builder singlePrice(String val) {
            singlePrice = val;
            return this;
        }

        public Builder courseDesc(String val) {
            courseDesc = val;
            return this;
        }

        public Builder coverUrl(String val) {
            coverUrl = val;
            return this;
        }

        public Builder coverStoreKey(String val) {
            coverStoreKey = val;
            return this;
        }

        public Builder coverNeedUpload(boolean val) {
            coverNeedUpload = val;
            return this;
        }

        public Builder courseSchedule(String val) {
            courseSchedule = val;
            return this;
        }

        public Builder publishOperationType(int val) {
            publishOperationType = val;
            return this;
        }

        public Builder singleClassDuration(String val) {
            singleClassDuration = val;
            return this;
        }

        public Builder progressStatus(int val) {
            progressStatus = val;
            return this;
        }

        public Builder controlOption(int val) {
            controlOption = val;
            return this;
        }

        public Builder goodsId(String val) {
            goodsId = val;
            return this;
        }

        public Builder releaseDate(long val) {
            releaseDate = val;
            return this;
        }

        public Builder sellDate(long val) {
            sellDate = val;
            return this;
        }

        public Builder guarantee(String val) {
            guarantee = val;
            return this;
        }

        public Builder router(String val) {
            router = val;
            return this;
        }

        public Builder retryCount(int val) {
            retryCount = val;
            return this;
        }

        public Builder uploadedPercent(float val) {
            uploadedPercent = val;
            return this;
        }

        public Builder rejectReason(String val) {
            rejectReason = val;
            return this;
        }

        public Builder viewCount(long val) {
            viewCount = val;
            return this;
        }

        public Builder likeCount(long val) {
            likeCount = val;
            return this;
        }

        public Builder commentCount(long val) {
            commentCount = val;
            return this;
        }

        public Builder collectCount(long val) {
            collectCount = val;
            return this;
        }

        public Builder sold(long val) {
            sold = val;
            return this;
        }

        public Builder salesVolume(double val) {
            salesVolume = val;
            return this;
        }

        public Builder publishSource(int val) {
            publishSource = val;
            return this;
        }

        public MajorCourseDBModel build() {
            return new MajorCourseDBModel(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.userId);
        dest.writeString(this.title);
        dest.writeString(this.interest);
        dest.writeString(this.industry);
        dest.writeByte(this.openBuy ? (byte) 1 : (byte) 0);
        dest.writeByte(this.joinConsumptionSecurityPlan ? (byte) 1 : (byte) 0);
        dest.writeString(this.classSize);
        dest.writeInt(this.openClassCondition);
        dest.writeString(this.minClassSize);
        dest.writeValue(this.confirmDate);
        dest.writeValue(this.startClassDate);
        dest.writeValue(this.endClassDate);
        dest.writeString(this.classLocation);
        dest.writeString(this.suitableLearnAge);
        dest.writeString(this.learnTarget);
        dest.writeString(this.suitablePeople);
        dest.writeString(this.majorCourseType);
        dest.writeString(this.price);
        dest.writeString(this.platformDividend);
        dest.writeString(this.courseNumber);
        dest.writeString(this.traingCard);
        dest.writeString(this.singlePrice);
        dest.writeString(this.courseDesc);
        dest.writeString(this.coverUrl);
        dest.writeString(this.coverStoreKey);
        dest.writeByte(this.coverNeedUpload ? (byte) 1 : (byte) 0);
        dest.writeString(this.courseSchedule);
        dest.writeInt(this.publishOperationType);
        dest.writeString(this.singleClassDuration);
        dest.writeInt(this.progressStatus);
        dest.writeInt(this.controlOption);
        dest.writeString(this.goodsId);
        dest.writeLong(this.releaseDate);
        dest.writeLong(this.sellDate);
        dest.writeString(this.guarantee);
        dest.writeString(this.router);
        dest.writeInt(this.retryCount);
        dest.writeFloat(this.uploadedPercent);
        dest.writeString(this.rejectReason);
        dest.writeLong(this.viewCount);
        dest.writeLong(this.likeCount);
        dest.writeLong(this.commentCount);
        dest.writeLong(this.collectCount);
        dest.writeLong(this.sold);
        dest.writeDouble(this.salesVolume);
        dest.writeInt(this.publishSource);
    }

    protected MajorCourseDBModel(Parcel in) {
        this.id = in.readString();
        this.userId = in.readString();
        this.title = in.readString();
        this.interest = in.readString();
        this.industry = in.readString();
        this.openBuy = in.readByte() != 0;
        this.joinConsumptionSecurityPlan = in.readByte() != 0;
        this.classSize = in.readString();
        this.openClassCondition = in.readInt();
        this.minClassSize = in.readString();
        this.confirmDate = (Long) in.readValue(Long.class.getClassLoader());
        this.startClassDate = (Long) in.readValue(Long.class.getClassLoader());
        this.endClassDate = (Long) in.readValue(Long.class.getClassLoader());
        this.classLocation = in.readString();
        this.suitableLearnAge = in.readString();
        this.learnTarget = in.readString();
        this.suitablePeople = in.readString();
        this.majorCourseType = in.readString();
        this.price = in.readString();
        this.platformDividend = in.readString();
        this.courseNumber = in.readString();
        this.traingCard = in.readString();
        this.singlePrice = in.readString();
        this.courseDesc = in.readString();
        this.coverUrl = in.readString();
        this.coverStoreKey = in.readString();
        this.coverNeedUpload = in.readByte() != 0;
        this.courseSchedule = in.readString();
        this.publishOperationType = in.readInt();
        this.singleClassDuration = in.readString();
        this.progressStatus = in.readInt();
        this.controlOption = in.readInt();
        this.goodsId = in.readString();
        this.releaseDate = in.readLong();
        this.sellDate = in.readLong();
        this.guarantee = in.readString();
        this.router = in.readString();
        this.retryCount = in.readInt();
        this.uploadedPercent = in.readFloat();
        this.rejectReason = in.readString();
        this.viewCount = in.readLong();
        this.likeCount = in.readLong();
        this.commentCount = in.readLong();
        this.collectCount = in.readLong();
        this.sold = in.readLong();
        this.salesVolume = in.readDouble();
        this.publishSource = in.readInt();
    }

    public static final Creator<MajorCourseDBModel> CREATOR = new Creator<MajorCourseDBModel>() {
        @Override
        public MajorCourseDBModel createFromParcel(Parcel source) {
            return new MajorCourseDBModel(source);
        }

        @Override
        public MajorCourseDBModel[] newArray(int size) {
            return new MajorCourseDBModel[size];
        }
    };
}
